package com.sls.sys.dao.impl;

import java.util.List;

import org.mybatis.spring.support.SqlSessionDaoSupport;

import com.sls.page.Pagination;
import com.sls.sys.querybean.base.BaseQuery;

public class SuperDAO<T> extends SqlSessionDaoSupport {
	/**
	 * 分页通用写法
	 * 
	 * @param pageStatement
	 *            分页的sql
	 * @param numberStatement
	 *            查询总数的sql
	 * @param query
	 *            查询bean 必须继承BaseQuery
	 * @return
	 */
	public <A> Pagination<A> queryPagination(String pageStatement,
			String numberStatement, BaseQuery query) {
		query.calculate();
		int rowCount = getSqlSession().selectOne(numberStatement, query);
		List<A> list = getSqlSession().selectList(pageStatement, query);
		Pagination<A> page = new Pagination<A>(query.getCurrentPage(),
				rowCount, query.getPageSize(), list);
		return page;
	}
}
